package com.cnswhy.cloud.server.core.vo;

import com.cnswhy.cloud.common.core.base.R;

import java.io.Serializable;
import java.util.Date;

/**
 * @author HuangHL
 * @date 2015/12/8
 * @see
 */
public class RespVo implements Serializable
{
    
    /**
     * 
     */
    private static final long serialVersionUID = 8341654184721022008L;
    
    /**
     * 状态码 0:成功
     */
    private int code = CODE_SUCCESS; // 处理状态
    
    /**
     * 失败
     */
    public static final int CODE_ERROR = -1;
    
    /**
     * 参数校验失败
     */
    public static final int VALIDATE_ERROR = 1;
    
    /**
     * 成功
     */
    public static final int CODE_SUCCESS = 0;
    
    /**
     * 其他状态
     */
    public static final int CODE_OTHER = 2;
    
    /**
     * 验证码失败
     */
    public static final int CODE_VERIFY = 3;
    
    /**
     * 密码错误
     */
    public static final int PASSWORD_ERROR = 4;
    
    /**
     * 密码过期
     */
    public static final int PASSWORD_OVERTIME_ERROR = 5;

    /** 密码未设置错误*/
    public static final int PASSWORD_CONFIG_ERROR = 6;
    
    /**
     * 登录超时
     */
    public static final int LOGIN_TIMEOUT = -2;
    
    /**
     * 消息
     */
    private String message = "SUCCESS"; // 返回信息
    
    private Object result;
    
    private Object subTotal;
    
    /**
     * 操作日志描述
     */
    private String logMsg;
    
    // 执行方法运行的时间
    private String runTime = new Date().toString();
    
    public RespVo()
    {
        super();
    }
    
    public RespVo(int code, String message)
    {
        this.code = code;
        this.message = message;
    }
    
    public RespVo(int code, String message, Object result)
    {
        this.code = code;
        this.message = message;
        this.result = result;
    }
    
    public RespVo(int code)
    {
        this.code = code;
    }
    
    public int getCode()
    {
        return code;
    }
    
    public void setCode(int code)
    {
        this.code = code;
    }
    
    public String getMessage()
    {
        return message;
    }
    
    public void setMessage(String message)
    {
        this.message = message;
    }
    
    public Object getResult()
    {
        return result;
    }
    
    public void setResult(Object result)
    {
        this.result = result;
    }
    
    public String getRunTime()
    {
        return runTime;
    }
    
    public void setRunTime(String runTime)
    {
        this.runTime = runTime;
    }
    
    public String getLogMsg()
    {
        return logMsg;
    }
    
    public void setLogMsg(String logMsg)
    {
        this.logMsg = logMsg;
    }

    public Object getSubTotal()
    {
        return subTotal;
    }

    public void setSubTotal(Object subTotal)
    {
        this.subTotal = subTotal;
    }

    /**
     * 请求成功消息
     *
     * @param data 结果
     * @return RPC调用结果
     */
    public static RespVo success(Object data) {
        return new RespVo(CODE_SUCCESS, "ok", data);
    }

    public static RespVo success() {
        return new RespVo(CODE_SUCCESS, "ok", true);
    }

    /**
     *
     * @param message
     * @return
     */
    public static RespVo fail(String message) {
        return new RespVo(CODE_ERROR, message);
    }

}
